package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.util.ConfigUtil;

import com.util.BODY;
import com.util.HttpRequest;
import com.util.JSONUtil;
import com.util.OpenKey;
import com.util.ReadConfig;
import com.util.SessionInfo;
//当前贷款信息
@Controller
@RequestMapping("/dqdkcontrller")
public class dqdkcontrller {


	private static final Logger logger = Logger.getLogger(dqdkcontrller.class);
	Map map  = new HashMap();
	List list = new ArrayList();
	  
	@RequestMapping("/test")
	@ResponseBody
	public String entryinterface(HttpServletRequest request, HttpServletResponse response , String limit ,String id,String start,String end,HttpSession session) throws IOException{
		//获取session对象
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		//读取配置文件路径
		Map reqMap = new HashMap();
		BODY b=new BODY();
		OpenKey opk=new OpenKey();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ110");
		//接口参数
		reqMap.put("OpenKey",sessionIn.getKEY());
		b.setGRZH(sessionIn.getGRZH());
		reqMap.put("BODY",b);
		String result=opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		logger.info("接口返回内容:"+retMap);
		if(retMap.get("RETURNCODE").equals("100")){
			Map resMap = (Map) retMap.get("body");
	    	List retlist = (List)resMap.get("RETDATA");
			if(result != null){
				if(retMap.get("RETURNCODE").equals("100")){
					map.put("code", 0);
					map.put("msg", null);
					map.put("data", retlist);
					list.add(retMap);
					response.setHeader("Content-type", "text/html;charset=UTF-8");
					response.setCharacterEncoding("UTF-8");
					System.out.println(JSONUtil.ToJsongString2(map));
					String jsonString = JSONUtil.ToJsongString2(map);
					PrintWriter pw = response.getWriter();
					pw.write(jsonString);
				}else{
					map.put("code", 1);
					map.put("CW", retMap.get("RETURNDESC").toString());
					response.setHeader("Content-type", "text/html;charset=UTF-8");
					response.setCharacterEncoding("UTF-8");
					String jsonString = JSONUtil.ToJsongString2(map);
					PrintWriter pw = response.getWriter();
					pw.write(jsonString);
				}
			}
		}else{
			map.put("code", 1);
			map.put("CW", retMap.get("RETURNDESC").toString());
			response.setHeader("Content-type", "text/html;charset=UTF-8");
			response.setCharacterEncoding("UTF-8");
			String jsonString = JSONUtil.ToJsongString2(map);
			PrintWriter pw = response.getWriter();
			pw.write(jsonString);
		}
		return null;
	}
}


